<template>
	<view class="content">
		<image class="logo" src="/static/logo.png"></image>
		<view class="text-area">
			<text class="title">{{title}}</text>
		</view>
		<form @submit="formSubmit">
			<view class="uni-form-item uni-row">
				<view class="title">用户名</view>
				<input class="uni-input" name="user" placeholder="请输入用户名" value="admin"/>
			</view>
			<view class="uni-form-item uni-row">
				<view class="title">密码</view>
				<input class="uni-input" name="pass" placeholder="请输入密码" value="123456"/>
			</view>
			<view class="uni-btn-v">
				<button form-type="submit">登录</button>
			</view>
		</form>
	</view>
</template>

<script>
	// import { http } from '@/api/service.js'; // 局部引入
	import Vue from 'vue'

	export default {
		data() {
			return {
				title: 'MSTN 无限仪表'
			}
		},
		onLoad() {

		},
		methods: {
			formSubmit: function(e) {
				console.log('form发生了submit事件，携带数据为：' + JSON.stringify(e.detail.value))
				var formdata = e.detail.value
				this.$http.post('/realhistorian/login', formdata).then(res => {
						const result = res.data.data;
						if (parseInt(result.code) == 0){
							Vue.prototype.token = result.token
							try {
							    uni.setStorageSync('login_user', e.detail.value.user);
								uni.redirectTo({
									url:"../basestation/basestation"
								})
							} catch (e) {
							    uni.showModal({
							    	content: '登录失败，请稍后再试',
							    	showCancel: false
							    })
							}
								
						} else {
							uni.showModal({
								content: '登录失败，请稍后再试',
								showCancel: false
							})
						}
					})
					.catch(err => {
						uni.showModal({
							content: '登录失败，请稍后再试',
							showCancel: false
						})
					})
			}
		}
	}
</script>

<style lang="scss">
@import '@/common/uni.css';
	
	.uni-form-item .title {
		margin-left: 20rpx;
		padding: 20rpx 0;
		width: 150rpx;
		font-size: 30rpx;
	}

	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.uni-btn-v {
		margin-left: 50rpx;
		margin-right: 50rpx;
		height: 40rpx;
	}
	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
	.uni-input {
	      background-color:#F1F1F1;
		  height: 60rpx;
		  border: 1px solid #DDD;
		  margin-right: 50rpx;
	}
</style>
